package com.welkom.everydate.domain;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import com.welkom.everydate.util.web.Header;
public class User implements UserDetails{
	@Header(headerText="用户编号")
	private long userId;
	@Header(headerText="用户账户")
	private String userAccount;
	@Header(headerText="登录名称")
	private String userName;
	private String userPassword;
	@Header(headerText="用户状态")
	private int userEnabled;
	private String userDesc;
	private List<Role> roles=new ArrayList<Role>();
	public User(long userId, String userAccount, String userName,
			String userPassword, int userEnabled, int issys, String userDesc) {
		this.userId = userId;
		this.userAccount = userAccount;
		this.userName = userName;
		this.userPassword = userPassword;
		this.userEnabled = userEnabled;
		this.userDesc = userDesc;
	}
	public User() {
		
	}
	/**
	 * @return the userId
	 */
	public long getUserId() {
		return userId;
	}
	/**
	 * @param userId the userId to set
	 */
	public void setUserId(long userId) {
		this.userId = userId;
	}
	/**
	 * @return the userAccount
	 */
	public String getUserAccount() {
		return userAccount;
	}
	/**
	 * @param userAccount the userAccount to set
	 */
	public void setUserAccount(String userAccount) {
		this.userAccount = userAccount;
	}
	/**
	 * @return the userName
	 */
	public String getUserName() {
		return userName;
	}
	/**
	 * @param userName the userName to set
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}
	/**
	 * @return the userPassword
	 */
	public String getUserPassword() {
		return userPassword;
	}
	/**
	 * @param userPassword the userPassword to set
	 */
	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}
	/**
	 * @return the userEnabled
	 */
	public int getUserEnabled() {
		return userEnabled;
	}
	/**
	 * @param userEnabled the userEnabled to set
	 */
	public void setUserEnabled(int userEnabled) {
		this.userEnabled = userEnabled;
	}
	/**
	 * @return the userDesc
	 */
	public String getUserDesc() {
		return userDesc;
	}
	/**
	 * @param userDesc the userDesc to set
	 */
	public void setUserDesc(String userDesc) {
		this.userDesc = userDesc;
	}
	/**
	 * @return the roles
	 */
	public List<Role> getRoles() {
		return roles;
	}
	/**
	 * @param roles the roles to set
	 */
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	public Collection<? extends GrantedAuthority> getAuthorities() {
		// TODO Auto-generated method stub
		return roles;
	}
	public String getPassword() {
		// TODO Auto-generated method stub
		return this.userPassword;
	}
	public String getUsername() {
		// TODO Auto-generated method stub
		return this.userName;
	}
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		boolean result=false;
		if(this.userEnabled==1){
			result=true;
		}
		return result;
	}
	@Override
	public boolean equals(Object object){
		if(!(object instanceof User)){
			return false;
		}
		User user=(User)object;
		if(!(user.getUserId()==this.getUserId())){
			return false;
		}
		if(!user.getUserName().equals(this.getUserName())){
			return false;
		}
		return true;
	}
}
